package com.frxuexi.sign

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.TimeUtils
import com.frxuexi.lib_base.mvvm.BaseActivity
import com.frxuexi.sign.databinding.ActivitySignBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.Timer
import kotlin.concurrent.timerTask

@Route(path = "/sign/SignActivity")
@AndroidEntryPoint
class SignActivity : BaseActivity<ActivitySignBinding,SignViewModel>() {
    var timer:Timer?=null
    override fun initData() {

    }

    override fun initView() {
        binding.btnSign.setOnClickListener {
            binding.btnSign.isEnabled=false
        }

        binding.conLocation.setOnClickListener {
            ARouter.getInstance().build("/sign/MapActivity").navigation()
        }

        lifecycleScope.launch(Dispatchers.IO) {
            timer= Timer()
            timer?.schedule(timerTask {
                val time = vm.getTime(System.currentTimeMillis())
                lifecycleScope.launch(Dispatchers.Main) {
                    binding.signTime.setText("${time}")
                }
            },0,1000)
        }

        val dateFont = vm.getDateFont(System.currentTimeMillis())
        val week = TimeUtils.getChineseWeek(System.currentTimeMillis()).replace("周","星期")
        binding.signDate.setText("${dateFont} ${week}")
    }

    override fun onDestroy() {
        super.onDestroy()
        if(timer!=null){
            timer?.cancel()
            timer==null
        }
    }

}